<template>
  <div>
    <Header></Header>
    <van-sticky>
      <van-nav-bar
        title="图文资讯"
        left-text="返回"
        left-arrow
        @click-left="onClickLeft"
        right-text="返回顶部"
        @click-right="onClickright"
      />
    </van-sticky>
    <div class="list">
      <div
        class="item"
        v-for="item in newsList"
        :key="item.id"
        @click="$router.push(`/goodsdesc/${item.id}`)"
      >
        <van-image width="3rem" height="3rem" :src="item.img_url" />
        <div class="item-right">
          <p class="item-right-hd">{{ item.title }}</p>
          <div class="item-right-bd">
            <span>发表时间：{{ item.add_time | fromdata }}</span>
            <p>点击{{ item.click }}</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getnewslist } from "../api";
import Header from "../components/header.vue";

export default {
  data() {
    return {
      newsList: [],
    };
  },
  async created() {
    const { data: res } = await getnewslist();
    console.log(res);
    this.newsList = res.message;
    console.log(this.newsList);
  },

  components: {
    Header,
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    onClickright() {
      //   console.log(1);
      window.scrollTo({
        top: 0,
        behavior: "smooth",
      });
    },
  },
};
</script>

<style lang="less" scoped>
.list {
  .item {
    display: flex;
    width: 100%;
    padding: 10px 0;
    .van-image {
      margin: 0 10px 0 0;
    }
    .item-right {
      flex: 1;
      .item-right-hd {
        font-size: 14px;
        color: #666;
      }
      .item-right-bd {
        display: flex;
        justify-content: space-between;
        margin-top: 10px;
        font-size: 16px;
        color: #61bdff;

        p {
        }
      }
    }
  }
}
</style>
